﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ThanhTu.GNC.Media.KQXS.DataAccess.DAL;
using System.Data;

namespace GNCMedia.KQXS.Admin.UserControlsAdmin
{
    public partial class ActionHotNews : System.Web.UI.UserControl
    {
        int pageindex = 1;
        int pageSize = 10;
        int rowncount = 0;
        BreakingNewsDAL brnews = new BreakingNewsDAL();
        protected void Page_Load(object sender, EventArgs e)
        {
            DataTable dt = brnews.selectAll_Page(pageindex, pageSize, ref rowncount);
            RepeaterHotNews.DataSource = dt;
            RepeaterHotNews.DataBind();
        }

        protected void btnAdd_Click(object sender, EventArgs e)
        {
            Response.Redirect("Addnews.aspx");
        }

        protected void RepeaterHotNews_ItemCommand(object source, RepeaterCommandEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
                BreakingNewsDAL brNewsDAL = new BreakingNewsDAL();
                int checkDEL = brNewsDAL.DeleteNews(Convert.ToInt32(e.CommandName.ToString()));
                if (checkDEL > 0)
                {
                    Page.ClientScript.RegisterStartupScript(this.GetType(), "ShowStatus", "javascript:alert('XÓA bản ghi  Thành công);", true);
                }
                else
                {
                    Page.ClientScript.RegisterStartupScript(this.GetType(), "ShowStatus", "javascript:alert('LỖI XÓA ,XIN VUI LÒNG THỬ LẠI);", true);
                }
            }
        }
    }
}